﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess.Classes;
using DataAccess;

namespace Webmau
{
    public partial class ChiTietBaiViet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateControls();
            }
        }

        private void PopulateControls()
        {
            string id = Request.QueryString["MaBaiViet"].ToString();
            BaiViet bv = BaiViet.LayBaiVietTheoID(id);
            lblTen.Text = bv.TenBaiViet.ToString();
            lblNoiDung.Text = bv.NoiDung;
            lbLoaiTin.Text = bv.LoaiTin;
            lbThoiGian.Text = bv.ThoiGian.ToShortDateString().ToString();
            imgHinh.ImageUrl = Link.ToHinhBVk(bv.Hinh);
            lnkIDNguoiDung.Text = bv.IDNguoiDung;


            lnkIDNguoiDung.NavigateUrl = ("TrangCaNhan.aspx" + "?ID=" + bv.IDNguoiDung);


        }
        protected void btnBinhLuan_Click(object sender, EventArgs e)
        {
            if (Session["id"] == null)
            {
                Response.Redirect("DangNhap.aspx");
            }
            else
            {
                if (Session["id"] != null)
                {
                    BinhLuanBaiViet bl = new BinhLuanBaiViet();
                    bl.MaBaiViet = Convert.ToInt32(Request.QueryString["MaBaiViet"].ToString());
                    bl.IDNguoiDung = Session["id"].ToString();
                    bl.NoiDung = txtNoidung.Text;
                    bl.Ngay = Convert.ToDateTime(DateTime.Now.ToShortDateString().ToString());
                    BinhLuanBaiViet.ThemBaiViet(bl);
                    Response.Redirect("ChiTietBaiViet.aspx" + "?MaBaiViet=" + Request.QueryString["MaBaiViet"].ToString());

                }
            }
        }
    }
}